//对当前点击对象(通道号按钮)更换css样式
$(document).ready(function(){
    $('#info .prompt').click(function(){
        if($(this).hasClass("new")){
             $(this).removeClass("new");
            $(this).addClass("prompt");
        }
       
        else{
            $(this).removeClass("prompt");
            $(this).addClass("new");
        }     
    })

    $('#bt .href').click(function(){
        window.location.href="bulk-delivery.html";
    })

    $('.member button').click(function(){
        window.location.href="login-head.html";
    })


    $('.checkbox #label-a').click(function(){
        if($(this).hasClass("label-check")){
             $(this).removeClass("label-check");
             $(this).addClass("label-a");
             $(".checkbox-a").prop("checked", false);
            
        }
       
        else{
            $(this).removeClass("label-a");
            $(this).addClass("label-check");
            $(".checkbox-a").prop("checked", true);
        }     
    })


    $('#check-b #label-b').click(function(){
        if($(this).hasClass("label-check")){
             $(this).removeClass("label-check");
             $(this).addClass("label-b");
             $(".checkbox-b").prop("checked", false);
            
        }
       
        else{
            $(this).removeClass("label-b");
            $(this).addClass("label-check");
            $(".checkbox-b").prop("checked", true);
        }     
    })


    $('.agreement .left label').click(function(){
        if($(this).hasClass("agree")){
             $(this).removeClass("agree");
           
             $(".checkbox-agree").prop("checked", false);
            
        }
       
        else{
         
            $(this).addClass("agree");
            $(".checkbox-agree").prop("checked", true);
        }     
    })

    $('.information .one').click(function(){
        $("#other").attr("checked",false);
        if($("#other").is(':checked') == true){
            $('.bt-in').removeAttr('disabled') 
            $('.top').removeAttr('disabled')
            $('.bottom').removeAttr('disabled')
        }else{
           
            $('.bt-in').attr('disabled',true) 
            $('.top').attr('disabled',true)
            $('.bottom').attr('disabled',true)
        }

        // if($(this).hasClass("agree")){
        //      $(this).removeClass("agree");
           
        //      $("#one").prop("checked", false);
            
        // }
       
        // else{
            $('.two').removeClass("agree");
            $('.other').removeClass("agree");
            $('.three').removeClass("agree");
            $(this).addClass("agree");
            $("#one").prop("checked", true);
        // }     
    })

    $('.information .two').click(function(){
        $("#other").attr("checked",false);
        if($("#other").is(':checked') == true){
            $('.bt-in').removeAttr('disabled') 
            $('.top').removeAttr('disabled')
            $('.bottom').removeAttr('disabled')
        }else{
           
            $('.bt-in').attr('disabled',true) 
            $('.top').attr('disabled',true)
            $('.bottom').attr('disabled',true)
        }

        // if($(this).hasClass("agree")){
        //      $(this).removeClass("agree");
           
        //      $("#two").prop("checked", false);
            
        // }
       
        // else{
           $('.one').removeClass("agree");
           $('.other').removeClass("agree");
             $('.three').removeClass("agree");
            $(this).addClass("agree");
            $("#two").prop("checked", true);
        //}     
    })

    $('.information .three').click(function(){
        $("#other").attr("checked",false);
        if($("#other").is(':checked') == true){
            $('.bt-in').removeAttr('disabled') 
            $('.top').removeAttr('disabled')
            $('.bottom').removeAttr('disabled')
        }else{
           
            $('.bt-in').attr('disabled',true) 
            $('.top').attr('disabled',true)
            $('.bottom').attr('disabled',true)
        }

        // if($(this).hasClass("agree")){
        //      $(this).removeClass("agree");
           
        //      $("#three").prop("checked", false);
            
        // }
       
        // else{
          $('.two').removeClass("agree");
             $('.one').removeClass("agree");
             $('.other').removeClass("agree");
            $(this).addClass("agree");
            $("#three").prop("checked", true);
        //}     
    })

    $('.information .other').click(function(){
        // if($(this).hasClass("agree")){
        //      $(this).removeClass("agree");
           
        //      $("#other").prop("checked", false);
            
        // }
       
        // else{
            $('.two').removeClass("agree");
            $('.one').removeClass("agree");
            $('.three').removeClass("agree");
            $(this).addClass("agree");
            $("#other").prop("checked", true);
        //}     
    })

    $('.checkbox-agree').click(function(){
        if($(".checkbox-agree").is(':checked') == true){
            $('.agree-label').addClass("agree");
        }else{
            $('.agree-label').removeClass("agree");
        }
    })

    $('.checkbox-a').click(function(){
        if($(".checkbox-a").is(':checked') == true){
            $('#label-a').removeClass("label-a");
            $('#label-a').addClass("label-check");
        }else{
            $('#label-a').removeClass("label-check");
            $('#label-a').addClass("label-a");
        }
    })

    $('.checkbox-b').click(function(){
        if($(".checkbox-b").is(':checked') == true){
            $('#label-b').addClass("label-check");
            $('#label-b').removeClass("label-b");
        }else{
            $('#label-b').removeClass("label-check");
            $('#label-b').addClass("label-b");
        }
    })
    var b = 1;
    $('.other').click(function(){
        if($("#other").is(':checked') == true){
            $(".bt-in").val(b);
            $('.bt-in').removeAttr('disabled') 
            $('.top').removeAttr('disabled')
            $('.bottom').removeAttr('disabled')
        }else{
           
            $('.bt-in').attr('disabled',true) 
            $('.top').attr('disabled',true)
            $('.bottom').attr('disabled',true)
        }
    })
        
   
    $("#bt-add").click(function(){
        if(b<30){
            b++;
            $(".bt-in").val(b);
        }
            
        
    });

    $("#bt-sub").click(function(){
        if(b>1){
            b--;
            $(".bt-in").val(b);
        }
    });


    $("*").click(function(){



        if($("#other").is(':checked') == true){


            $('.information .other').addClass("agree");

            $(".bt-in").val(b);
            $('.bt-in').removeAttr('disabled') 
            $('.top').removeAttr('disabled')
            $('.bottom').removeAttr('disabled')
        }else{
            b = 0;
            $(".bt-in").val("");
            $('.bt-in').attr('disabled',true) 
            $('.top').attr('disabled',true)
            $('.bottom').attr('disabled',true)
             $('.information .other').removeClass("agree");
        }

        if($("#one").is(':checked') == true){
            $('.information .one').addClass("agree");
        }else{
            $('.information .one').removeClass("agree");
        }

        if($("#three").is(':checked') == true){
            $('.information .three').addClass("agree");
        }else{
            $('.information .three').removeClass("agree");
        }

        if($("#two").is(':checked') == true){
            $('.information .two').addClass("agree");
        }else{
            $('.information .two').removeClass("agree");
        }




    });

    $('#info .prompt').click(function(){
        if($(this).hasClass("new")){
            $(this).find('input').attr('name','remarksTip');
        }

        else{
            $(this).find('input').attr('name','a');
        }
    })

    $(".middle-regulations .button").click(function(){
        $("#login-false").hide();
        $("#login-true").show();
    });

});



// Get the modal
var modal = document.getElementById('myModal');

// Get the button that opens the modal
var btn = document.getElementById("myBtn");

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks the button, open the modal
btn.onclick = function() {
    modal.style.display = "block";
}

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
    modal.style.display = "none";
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
    if (event.target == modal) {
        modal.style.display = "none";
    }
}

// Get the modal
var modal2 = document.getElementById('myModal1');

// Get the button that opens the modal
var btn2 = document.getElementById("myBtn1");

// Get the <span> element that closes the modal
var span2 = document.getElementsByClassName("close")[0];

// When the user clicks the button, open the modal
btn2.onclick = function() {
    modal2.style.display = "block";
}

// When the user clicks on <span> (x), close the modal
span2.onclick = function() {
    modal2.style.display = "none";
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
    if (event.target == modal2) {
        modal2.style.display = "none";
    }
}

// Get the modal
var modal3 = document.getElementById('myModal2');

// Get the button that opens the modal
var btn3 = document.getElementById("myBtn2");

// Get the <span> element that closes the modal
var span3 = document.getElementsByClassName("close")[0];

// When the user clicks the button, open the modal
btn3.onclick = function() {
    modal3.style.display = "block";
}

// When the user clicks on <span> (x), close the modal
span3.onclick = function() {
    modal3.style.display = "none";
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event3) {
    if (event3.target == modal3) {
        modal3.style.display = "none";
    }
}

// Get the modal
var modal4 = document.getElementById('myModal3');

// Get the button that opens the modal
var btn4 = document.getElementById("myBtn3");

// Get the <span> element that closes the modal
var span4 = document.getElementById("close3");

// When the user clicks the button, open the modal
btn4.onclick = function() {
    modal4.style.display = "block";
}

// When the4 user clicks on <span> (x), close the modal
span4.onclick = function() {
    modal4.style.display = "none";
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event4) {
    if (event4.target == modal4 || event4.target == modal ||  event4.target == modal2 || event4.target == modal3) {
        modal.style.display = "none";
        modal2.style.display = "none";
        modal3.style.display = "none";
        modal4.style.display = "none";
    }
}


$(function(){

    $("#send-phone-text").blur(function(){
        
        let phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
        let sendPhone = $.trim($('#send-phone-text').val());
        if (sendPhone=="") {
            // layer.msg("请输入有效的手机号码");
            $('#send-phone-text').css({border:"solid 1px red"});
            $('#send-phone-p').html("手机号不能为空");
        }else{
            if (!phoneReg.test(sendPhone)) {
                $('#send-phone-text').css({border:"solid 1px blue"});
                $('#send-phone-p').html("");
                $('#send-phone-text').css({border:"solid 1px red"});
                $('#send-phone-p').html("请输入正确的手机号");
            }else{
                $('#send-phone-text').css({border:"solid 1px #67C23A"});
                $('#send-phone-p').html("");
            }
        }   
    });

    $("#recevice-phone-text").blur(function(){
        let phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
        let recevicePhone = $.trim($('#recevice-phone-text').val());
        if (recevicePhone=="") {
            // layer.msg("请输入有效的手机号码");
            $('#recevice-phone-text').css({border:"solid 1px red"});
            $('#recevice-phone-p').html("手机号不能为空");
        }else{
            if (!phoneReg.test(recevicePhone)) {
                $('#recevice-phone-text').css({border:"solid 1px blue"});
                $('#recevice-phone-p').html("");
                $('#recevice-phone-text').css({border:"solid 1px red"});
                $('#recevice-phone-p').html("请输入正确的手机号");
            }else{
                $('#recevice-phone-text').css({border:"solid 1px #67C23A"});
                $('#recevice-phone-p').html("");
            }
        }   
    });

    $("#send-name-text").blur(function(){
        let sendName = $.trim($('#send-name-text').val());
        if (sendName=="") {
            $('#send-name-text').css({border:"solid 1px red"});
            $('#send-name-p').html("寄件人姓名不能为空");
           
        }else{
            $('#send-name-text').css({border:"solid 1px #67C23A"});
            $('#send-name-p').html("");
            
             
        }   
    });

    $("#send-area-text").blur(function(){
        let sendArea = $.trim($('#send-area-text').val());
        if (sendArea=="") {
            $('#send-area-text').css({border:"solid 1px red"});
            $('#send-area-p').html("请输入所属区域");
           
        }else{
            $('#send-area-text').css({border:"solid 1px #67C23A"});
            $('#send-area-p').html("");
            
             
        }   
    });

    $("#send-address-text").blur(function(){
        let sendAddress = $.trim($('#send-address-text').val());
        if (sendAddress=="") {
            $('#send-address-text').css({border:"solid 1px red"});
            $('#send-address-p').html("请输入详细地址");
           
        }else{
            $('#send-address-text').css({border:"solid 1px #67C23A"});
            $('#send-address-p').html("");
            
             
        }   
    });

    $("#recevice-name-text").blur(function(){
        let receviceName = $.trim($('#recevice-name-text').val());
        if (receviceName=="") {
            $('#recevice-name-text').css({border:"solid 1px red"});
            $('#recevice-name-p').html("收件人姓名不能为空");
           
        }else{
            $('#recevice-name-text').css({border:"solid 1px #67C23A"});
            $('#recevice-name-p').html("");
            
             
        }   
    });

    $("#recevice-area-text").blur(function(){
        let receviceArea = $.trim($('#recevice-area-text').val());
        if (receviceArea=="") {
            $('#recevice-area-text').css({border:"solid 1px red"});
            $('#recevice-area-p').html("请输入所属区域");
           
        }else{
            $('#recevice-area-text').css({border:"solid 1px #67C23A"});
            $('#recevice-area-p').html("");
            
             
        }   
    });

    $("#recevice-address-text").blur(function(){
        let receviceAddress = $.trim($('#recevice-address-text').val());
        if (receviceAddress=="") {
            $('#recevice-address-text').css({border:"solid 1px red"});
            $('#recevice-address-p').html("请输入详细地址");
           
        }else{
            $('#recevice-address-text').css({border:"solid 1px #67C23A"});
            $('#recevice-address-p').html("");
            
             
        }   
    });

    $("#form").submit(function(){

        if(!$(".checkbox-agree").prop("checked")){
            layer.msg("请先勾选协议");
            return false;
        }

        let flag = 0;
        let phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
        let sendPhone = $.trim($('#send-phone-text').val());
        if (sendPhone=="") {
            // layer.msg("请输入有效的手机号码");
            $('#send-phone-text').css({border:"solid 1px red"});
            $('#send-phone-p').html("手机号不能为空");
            flag = 1;
        }else{
            if (!phoneReg.test(sendPhone)) {
                $('#send-phone-text').css({border:"solid 1px blue"});
                $('#send-phone-p').html("");
                $('#send-phone-text').css({border:"solid 1px red"});
                $('#send-phone-p').html("请输入正确的手机号");
                flag = 1;
            }else{
                $('#send-phone-text').css({border:"solid 1px #67C23A"});
                $('#send-phone-p').html("");
            }
        }   

        let recevicePhone = $.trim($('#recevice-phone-text').val());
        if (recevicePhone=="") {
            // layer.msg("请输入有效的手机号码");
            $('#recevice-phone-text').css({border:"solid 1px red"});
            $('#recevice-phone-p').html("手机号不能为空");
            flag = 1;
        }else{
            if (!phoneReg.test(recevicePhone)) {
                $('#recevice-phone-text').css({border:"solid 1px blue"});
                $('#recevice-phone-p').html("");
                $('#recevice-phone-text').css({border:"solid 1px red"});
                $('#recevice-phone-p').html("请输入正确的手机号");
                flag = 1;
            }else{
                $('#recevice-phone-text').css({border:"solid 1px #67C23A"});
                $('#recevice-phone-p').html("");
            }
        }   

        let sendName = $.trim($('#send-name-text').val());
        if (sendName=="") {
            $('#send-name-text').css({border:"solid 1px red"});
            $('#send-name-p').html("寄件人姓名不能为空");
            flag = 1;
            
        }else{
            $('#send-name-text').css({border:"solid 1px #67C23A"});
            $('#send-name-p').html("");
            
                
        }   

        let sendArea = $.trim($('#send-area-text').val());
        if (sendArea=="") {
            $('#send-area-text').css({border:"solid 1px red"});
            $('#send-area-p').html("请输入所属区域");
            flag = 1;
            
        }else{
            $('#send-area-text').css({border:"solid 1px #67C23A"});
            $('#send-area-p').html("");
            
                
        }   

        let sendAddress = $.trim($('#send-address-text').val());
        if (sendAddress=="") {
            $('#send-address-text').css({border:"solid 1px red"});
            $('#send-address-p').html("请输入详细地址");
            flag = 1;
            
        }else{
            $('#send-address-text').css({border:"solid 1px #67C23A"});
            $('#send-address-p').html("");
            
                
        }   

        let receviceName = $.trim($('#recevice-name-text').val());
        if (receviceName=="") {
            $('#recevice-name-text').css({border:"solid 1px red"});
            $('#recevice-name-p').html("收件人姓名不能为空");
            flag = 1;
            
        }else{
            $('#recevice-name-text').css({border:"solid 1px #67C23A"});
            $('#recevice-name-p').html("");
            
                
        }   

        let receviceArea = $.trim($('#recevice-area-text').val());
        if (receviceArea=="") {
            $('#recevice-area-text').css({border:"solid 1px red"});
            $('#recevice-area-p').html("请输入所属区域");
            flag = 1;
            
        }else{
            $('#recevice-area-text').css({border:"solid 1px #67C23A"});
            $('#recevice-area-p').html("");
            
                
        }   

        let receviceAddress = $.trim($('#recevice-address-text').val());
        if (receviceAddress=="") {
            $('#recevice-address-text').css({border:"solid 1px red"});
            $('#recevice-address-p').html("请输入详细地址");
            flag = 1;
            
        }else{
            $('#recevice-address-text').css({border:"solid 1px #67C23A"});
            $('#recevice-address-p').html("");
                        
        }
        if(flag == 1){
            return false;
        }else{
            return true;
        }
    });


});
